<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:th="http://www.thymeleaf.org">
<head>
	<div th:replace="commons/html-header"></div>
</head>
<body class="skin-1">

<div th:replace="commons/head"></div>



<div class="main-container" id="main-container">

	<script type="text/javascript">

        try{gds.settings.check('main-container' , 'fixed')}catch(e){}

	</script>

	<div class="main-container-inner">

		<a class="menu-toggler" id="menu-toggler" href="#">

			<span class="menu-text"></span>

		</a>



		<div th:replace="admin/admin-menu"></div>

		<div class="main-content">

			<div class="breadcrumbs" id="breadcrumbs">

				<script type="text/javascript">

                    try{gds.settings.check('breadcrumbs' , 'fixed')}catch(e){}

				</script>



				<ul class="breadcrumb">
					<li>
						<i class="icon-home home-icon"></i>
						<a href="#">Home</a>
					</li>
					<li>
						审核管理
					</li>
				</ul><!-- .breadcrumb -->

			</div>
			<div class="page-content">

				<div class="page-header">
					<form class="form-inline" role="form">
						<div class="form-group">
							<label class="sr-only" for="c_VERIFY_TYPE">审核类型</label>
							<select class="form-control" id="c_VERIFY_TYPE">
								<option value=""> 全部 </option>
								<option th:each="dict:${verifyTypes}" th:value="${dict.c_DICT_ITEM_VALUE}" th:text="${dict.c_DICT_ITEM_NAME}"></option>
							</select>
						</div>
						<div class="form-group">
							<label class="sr-only" for="c_VERIFY_STATUS">状态</label>
							<select class="form-control" id="c_VERIFY_STATUS">
								<option value=""> 全部 </option>
								<option th:each="dict:${verifyStatus}" th:value="${dict.c_DICT_ITEM_VALUE}" th:text="${dict.c_DICT_ITEM_NAME}"></option>
							</select>
						</div>
						<button type="button" id="btn-search" class="btn btn-sm btn-info"><i class="icon-search"></i>查询</button>
					</form>

				</div>

				<div class="row">

					<div class="col-xs-12">
						<div class="table-responsive">

							<table id="tbl" class="table table-striped table-bordered table-hover">
								<thead>
								<tr>

									<th class="center">序号</th>
									<th>公司名称</th>
									<th>应用名称</th>
									<th>接口名称</th>
									<th>审核类型</th>
									<th>状态</th>
									<th>提交人</th>
									<th>提交时间</th>
									<th></th>
								</tr>
								</thead>
								<tbody>

								</tbody>
							</table>
						</div><!-- /.table-responsive -->
					</div><!-- /.col -->

				</div><!-- /.row -->

			</div><!-- /.page-content -->

		</div><!-- /.main-content -->

	</div><!-- /.main-container-inner -->

	<div th:replace="admin/verify-modal"></div>
	<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
		<i class="icon-double-angle-up icon-only bigger-110"></i>
	</a>

</div><!-- /.main-container -->



<!-- basic scripts -->
<div th:replace="commons/html-js"></div>

<!-- inline scripts related to this page -->

<script>
    var c_VERIFY_TYPE;
    var c_VERIFY_STATUS;

    var appRoleId;
    var appId;

    var lastTD ='<td class="clearfix"><button class="btn btn-xs btn-info" onclick="toVerify(\'{{0}}\',\'{{1}}\')" ><i class="icon-edit bigger-120"></i>审核 </button></td>';
    queryForList = function() {
        var reqdata = {};
        if ('' != c_VERIFY_STATUS) {
            $.extend(reqdata,{c_VERIFY_STATUS:c_VERIFY_STATUS});
        }
        if ('' != c_VERIFY_TYPE) {
            $.extend(reqdata,{c_VERIFY_TYPE:c_VERIFY_TYPE});
        }
        $.post(contextPath + "/verify/list" , reqdata, function (data) {
            var html = '';
            //<![CDATA[
            if (null != data && data.length > 0) {
                for (var i = 0; i<data.length; i ++) {
                    html += '<tr>';
                    html += ('' +
                    '<td class="center">' + (i+1) + '</td>' +
                    '<td><div title="' + data[i].c_COMPANY_NAME + '">' + data[i].c_COMPANY_NAME + '</div></td>' +
                    '<td><div title="' + (null == data[i].c_APP_NAME ? '' : data[i].c_APP_NAME) + '">' + (null == data[i].c_APP_NAME ? '' : data[i].c_APP_NAME) + '</div></td>' +
                    '<td><div title="' + (null == data[i].c_INTERF_NAME ? '' : data[i].c_INTERF_NAME) + '">' + (null == data[i].c_INTERF_NAME ? '' : data[i].c_INTERF_NAME) + '</div></td>' +
                    '<td><div title="' + data[i].c_VERIFY_TYPE_NAME + '">' + data[i].c_VERIFY_TYPE_NAME + '</div></td>' +
                    '<td><div title="' + data[i].c_VERIFY_STATUS_NAME + '">' + data[i].c_VERIFY_STATUS_NAME + '</div></td>' +
                    '<td><div title="' + data[i].c_SUBMIT_USER + '">' + data[i].c_SUBMIT_USER + '</div></td>' +
                    '<td><div title="' + data[i].c_CREATE_TIME + '">' + data[i].c_CREATE_TIME + '</div></td>');
                    if ('VERIFY_STATUS_APPROVED' == data[i].c_VERIFY_STATUS) {
                        html += '<td></td>'
                    } else {
                        html += lastTD.replace(/\{\{0\}\}/gi,data[i].c_VERIFY_ID).replace(/\{\{1\}\}/gi,data[i].c_VERIFY_TYPE);;
                    }

                    html += '</tr>';
                }

            }
            // ]]>
            $("#tbl tbody").html(html);
        })
    };
    toVerify = function (c_VERIFY_ID, c_VERIFY_TYPE) {
        appId = null;
        appRoleId = null;
        $("#verifyId").val(c_VERIFY_ID);
        if ('VERIFY_TYPE_USER_REGISTER' == c_VERIFY_TYPE) {
            //$("#user_modal").modal();
            $("#title_label").text("账户注册审核")
            showUserVerify(c_VERIFY_ID);
        } else if('VERIFY_TYPE_COMPANY_REGISTER' == c_VERIFY_TYPE) {
            //$("#user_modal").modal();
            $("#company_modal_title").text("厂家注册审核")
            showCompanyrVerify(c_VERIFY_ID);

        } else if ('VERIFY_TYPE_APP_REGISTER' == c_VERIFY_TYPE || 'VERIFY_TYPE_APP_OFFLINE' == c_VERIFY_TYPE|| 'VERIFY_TYPE_APP_CHANGED' == c_VERIFY_TYPE) {
            var title = "";
            $("#app_offline").parent().hide();
            $("#app_role").parent().show();
            if ('VERIFY_TYPE_APP_REGISTER' == c_VERIFY_TYPE){
                title = "应用注册审核";
            } else if ('VERIFY_TYPE_APP_OFFLINE' == c_VERIFY_TYPE){
                title = "应用下线审核"
                $("#app_role").parent().hide();
                $("#app_offline").parent().show();
            } else {
                title ="应用变更审核"};
            $("#app_modal_title").text(title);
            showAPPVerify(c_VERIFY_ID,c_VERIFY_TYPE);
            //$("#app_verify_modal").modal();
        }  else if ('VERIFY_TYPE_INTERF_REGISTER' == c_VERIFY_TYPE || 'VERIFY_TYPE_INTERF_OFFLINE' == c_VERIFY_TYPE|| 'VERIFY_TYPE_INTERF_CHANGED' == c_VERIFY_TYPE) {
            var title = "";
            $("#interf_offline").parent().hide();
            $("#interf_roles").parent().show();
            if ('VERIFY_TYPE_INTERF_REGISTER' == c_VERIFY_TYPE){
                title = "接口注册审核";

            } else if ('VERIFY_TYPE_INTERF_OFFLINE' == c_VERIFY_TYPE){
                title = "接口下线审核"
                $("#app_offline").parent().show();
                $("#interf_roles").parent().hide();
            } else {
                title ="接口变更审核"};
            $("#interf_modal_title").text(title);
            showInterfVerify(c_VERIFY_ID,c_VERIFY_TYPE);
            //$("#app_verify_modal").modal();
        }
    };
    showUserVerify = function (c_VERIFY_ID) {
        $.post(contextPath + "/verify/u/" + c_VERIFY_ID , function (data) {
            //<![CDATA[
            if (null != data && null != data.userInfo) {
                $("#user_verifyId").val(c_VERIFY_ID);
                $("#td_C_LOGIN_NAME").html(data.userInfo.c_LOGIN_NAME);
                $("#td_C_USER_EMAIL").html(data.userInfo.c_USER_EMAIL);
                $("#td_C_COMPANY_NAME").html(data.userInfo.c_COMPANY_NAME);
                $("#user_verify_modal").modal();
            } else {
                bootbox.alert({
                    buttons: {
                        ok: {
                            label: '确定',
                            className: 'btn-sm btn-primary'
                        }
                    },
                    title :"确认",
                    message :'审核失败，未能读取到审核信息，请刷新页面后重试！',
                    size: 'small'
                });
            }
            // ]]>
        });
    };
    showCompanyrVerify = function (c_VERIFY_ID) {
        $.post(contextPath + "/verify/com/" + c_VERIFY_ID , function (data) {
            // <![CDATA[
            if (null != data && null != data.companyInfo) {
                $("#companyVerifyId").val(c_VERIFY_ID);

                $("#companyTable tr").each(function(index, obj) {
                    var _name = $(this).find("td:eq(1)").attr("name");
                    if (null != _name) {
                        $(this).find("td:eq(1)").text(data.companyInfo[_name]);
                    }

                });
                $("#company_verify_modal").modal();
            } else {
                bootbox.alert({
                    buttons: {
                        ok: {
                            label: '确定',
                            className: 'btn-sm btn-primary'
                        }
                    },
                    title :"确认",
                    message :'审核失败，未能读取到审核信息，请刷新页面后重试！',
                    size: 'small'
                });
            }
            // ]]>
        });
    }
    showInterfVerify = function (c_VERIFY_ID, c_VERIFY_TYPE) {
        $.post(contextPath + "/verify/interf/" + c_VERIFY_ID , function (data) {
            // <![CDATA[
            $("#interf_verify_modal").modal();
            $("#interfVerifyId").val(c_VERIFY_ID);
            if (null != data && null != data.interfsInfo) {
                if (data.interfsInfo.c_INTERF_UNIFY == 1) {
                    $("#rsp_INTERF_SERVICE").parents("tr").show();
                } else {
                    $("#rsp_INTERF_SERVICE").parents("tr").hide();
                }
                $("#interf_verify_modal table").find("div,span").each(function (index, objc) {
                    var obj = data.interfsInfo;
                    if (null != $(this).attr("name") && null != obj[$(this).attr("name")]) {
                        if ($(this).attr("name") == 'c_INTERF_UNIFY') {
                            $(this).text( data.interfsInfo.c_INTERF_UNIFY == 1 ? '是' : '否');
                        } else {
                            $(this).text(obj[$(this).attr("name")]);
                        }
                    }
                });
                if ("VERIFY_TYPE_INTERF_CHANGED" == c_VERIFY_TYPE) {
                    $("#interf_changed").css("display" , "block");
                    $("#interf_no_change").css("display" , "none");

                    $("#after_INTERF_ENDPOINT").text(null == data.changedServer.c_INTERF_ENDPOINT ? data.interfsInfo.c_INTERF_ENDPOINT : data.changedServer.c_INTERF_ENDPOINT);
                    $("#after_INTERF_NAMEP").text(null == data.changedServer.c_INTERF_NAMEP ? data.interfsInfo.c_INTERF_NAMEP : data.changedServer.c_INTERF_NAMEP);
                    $("#after_INTERF_METHOD_NAME").text(null == data.changedServer.c_INTERF_METHOD_NAME ? data.interfsInfo.c_INTERF_METHOD_NAME : data.changedServer.c_INTERF_METHOD_NAME);
                    $("#after_INTERF_HTTP_METHOD").text(null == data.changedServer.c_INTERF_HTTP_METHOD ? data.interfsInfo.c_INTERF_HTTP_METHOD : data.changedServer.c_INTERF_HTTP_METHOD);
                    $("#after_INTERF_PROTOCOL").text(data.interfsInfo.c_INTERF_PROTOCOL);
                } else {
                    $("#interf_changed").css("display" , "none");
                    $("#interf_no_change").css("display" , "block");
                }
                $("#interf_offline_reason .widget-main").text(data.interfOffLineRemark);

                if (null != data.interfsInfo.iparams) {
                    var iparams = '';
                    var prm;
                    for(var i = 0; i< data.interfsInfo.iparams.length; i++) {
                        var iparams_name ='';
                        prm = data.interfsInfo.iparams[i];
                        if (prm.c_IPARAMS_REMARK != null){
                            iparams_name = prm.c_IPARAMS_REMARK;
                        }
                        iparams += '<tr><td>' + prm.c_IPARAMS_NAME + '</td><td>' + iparams_name + '</td><td>' + prm.c_IPARAMS_DATATYPE_NAME + '</td><td>' + (null == prm.c_IPARAMS_SERVICE  ? '' : prm.c_IPARAMS_SERVICE)+ '</td></tr>'
                    }
                    $("#serv_tab").html(iparams);
                }
            }
            // ]]>
        });
    };
    showAPPVerify = function (c_VERIFY_ID,c_VERIFY_TYPE) {
//            <![CDATA[
        $.post(contextPath + "/verify/app/" + c_VERIFY_ID , function (data) {
            if (null != data) {
//                    $("#c_APP_ID").html(data.appInfo.c_APP_ID);
                $("#c_APP_NAME").val(data.appInfo.c_APP_NAME);
                $("#c_APP_TYPE_NAME").val(data.appInfo.c_APP_TYPE_NAME);
                $("#c_COMPANY_NAME").val(data.appInfo.c_COMPANY_NAME);
                $("#c_APP_REMARK").val(data.appInfo.c_APP_REMARK);

                var html = "";
                if (null != data.appInfo.appIps && data.appInfo.appIps.length > 0) {
                    var ip;
                    for (var i = 0; i< data.appInfo.appIps.length;i++) {
                        ip = data.appInfo.appIps[i];
                        html += '<tr><td>' + ip.c_APP_IP +'</td><td><div title="' + (null == ip.c_APPIP_REMARK ? '' : ip.c_APPIP_REMARK)  +'">' + (null == ip.c_APPIP_REMARK ? '' : ip.c_APPIP_REMARK)  +'</div></td></tr>';
                    }
                }


                if ('VERIFY_TYPE_APP_CHANGED' == c_VERIFY_TYPE) {
                    var html2 = "";//
                    $("#app_change").show();
                    $("#app_not_change").hide();

                    if (null != data.changeIps && data.changeIps.length > 0) {
                        var ip;
                        for (var i = 0; i< data.changeIps.length;i++) {
                            ip = data.changeIps[i];
                            html2 += '<tr><td>' + ip.c_APP_IP +'</td><td><div title="' + (null == ip.c_APPIP_REMARK ? '' : ip.c_APPIP_REMARK)  +'">' + (null == ip.c_APPIP_REMARK ? '' : ip.c_APPIP_REMARK)  +'</div></td></tr>';
                        }
                    }
                    $("#app_change table[name=before_change] tbody").html(html);
                    $("#app_change table[name=after_change] tbody").html(html2);
                } else {
                    $("#app_change").hide();
                    $("#app_not_change").show();

                    $("#app_not_change table tbody").html(html);
                    $("#app_offline_reason .widget-main").html(data.appOffLineRemark);
                }

                if (null != data.roles && data.roles.length > 0) {
                    html = '';
                    for (var i = 0; i< data.roles.length; i++) {
                        html += "<div class='col-sm-4'><input name='app_role' type='radio' value='" + data.roles[i].c_ROLE_ID + "' ";
                        if (data.appInfo.c_ROLE_ID == data.roles[i].c_ROLE_ID) {
                            html += " checked='checked' ";
                        }
                        html +=" onclick='checkRole(\"" + data.roles[i].c_ROLE_ID + "\",\"" + data.appInfo.c_APP_ID + "\")' /> " + data.roles[i].c_ROLE_NAME + "</div>";
                    }
                    $("#app_role_list .row").html(html);
                }
                $("#app_verify_modal").modal();
            } else {
                bootbox.alert({
                    buttons: {
                        ok: {
                            label: '确定',
                            className: 'btn-sm btn-primary'
                        }
                    },
                    title :"确认",
                    message :'审核失败，未能读取到审核信息，请刷新页面后重试！',
                    size: 'small'
                });
            }
        });
        // ]]>
    };

    verify = function(c_VERIFY_ID,c_VERIFY_RESULT) {
        var msg = '确认审核此条申请' + (c_VERIFY_RESULT=='Y'?'通过':'不通过') + '?';
        bootbox.confirm({
            buttons: {
                confirm: {
                    label: '确定',
                    className: 'btn-sm btn-primary'
                },
                cancel: {
                    label: '取消',
                    className: 'btn-sm btn-smbtn-default'
                }
            },
            title :"确认",
            message : msg,
            size: 'small',
            callback : function (result) {
                if (result){

                    $.post(contextPath + "/verify/"+c_VERIFY_ID+"/"+c_VERIFY_RESULT,{c_APP_ID:appId,c_ROLE_ID:appRoleId},function (data) {
                        appId = null;
                        appRoleId = null;
                        //<![CDATA[
                        if (null != data && data.code == 0) {
                            bootbox.alert({
                                buttons: {
                                    ok: {
                                        label: '确定',
                                        className: 'btn-sm btn-primary'
                                    }
                                },
                                title :"确认",
                                message :'审核成功！',
                                size: 'small',
                                callback : function () {
                                    $("#user_verify_modal").modal('hide');
                                    $("#app_verify_modal").modal('hide');
                                    $("#interf_verify_modal").modal('hide');
                                    $("#company_verify_modal").modal('hide');
                                    queryForList();
                                }
                            })
                        } else {
                            bootbox.alert({
                                buttons: {
                                    ok: {
                                        label: '确定',
                                        className: 'btn-sm btn-primary'
                                    }
                                },
                                title :"确认",
                                message :'审核失败，未能读取到审核信息，请刷新页面后重试！',
                                size: 'small'
                            })
                        }
                        //	]]>
                    })
                }
            }
        });

    };

    checkRole = function(roleId, app) {
        appRoleId = roleId;
        appId = app;
    }
    $(document).ready(function () {

        queryForList();
        $("#btn-search").on("click" , function () {
            c_VERIFY_TYPE = $("#c_VERIFY_TYPE").val();
            c_VERIFY_STATUS = $("#c_VERIFY_STATUS").val();
            queryForList();
        });

        $("#btn-approved").on("click" , function () {
            var verifyId = $("#verifyId").val();
            verify(verifyId, "Y");
        });
        $("#btn-not-approved").on("click" , function () {
            var verifyId = $("#verifyId").val();
            verify(verifyId, "N");
        })
        $("#com-approved").on("click" , function () {
            var verifyId = $("#companyVerifyId").val();
            verify(verifyId, "Y");
        });
        $("#com-not-approved").on("click" , function () {
            var verifyId = $("#companyVerifyId").val();
            verify(verifyId, "N");
        })
        $("#interf-approved").on("click" , function () {
            var verifyId = $("#interfVerifyId").val();
            verify(verifyId, "Y");
        });
        $("#interf-not-approved").on("click" , function () {
            var verifyId = $("#interfVerifyId").val();
            verify(verifyId, "N");
        })

        $("#btn-approved-user").on("click" , function () {
            var verifyId = $("#user_verifyId").val();
            verify(verifyId, "Y");
        });
        $("#btn-not-approved-user").on("click" , function () {
            var verifyId = $("#user_verifyId").val();
            verify(verifyId, "N");
        })

    });
</script>
</body>

</html>